package cn.wlj.origin.topic;

import cn.wlj.origin.ConnectUtil;
import cn.wlj.origin.Constant;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

/**
 * @ClassName Sender
 * @Description TODO
 * @Author WLJ
 * @Date 2024/1/16 20:21
 * @Version 1.0
 */
public class Sender {
    public static void main(String[] args) throws Exception {
        // 交换机名称
        String exchangeName = Constant.Topic.EXCHANGE_NAME;

        // 获取连接
        Connection connection = ConnectUtil.getConnection();
        // 获取通道
        Channel channel = connection.createChannel();
        // 声明交换机
        channel.exchangeDeclare(exchangeName, BuiltinExchangeType.TOPIC);
        // 新增消息
        String insertMsg = "新增消息";
        channel.basicPublish(exchangeName, Constant.Topic.INSERT_ROUTING_KEY, null, insertMsg.getBytes());;
        System.out.println("【" + insertMsg + "】发送成功");
        // 修改消息
        String updateMsg = "修改消息";
        channel.basicPublish(exchangeName, Constant.Topic.UPDATE_ROUTING_KEY, null, updateMsg.getBytes());;
        System.out.println("【" + updateMsg + "】发送成功");
        // 删除消息
        String deleteMsg = "删除消息";
        channel.basicPublish(exchangeName, Constant.Topic.DELETE_ROUTING_KEY, null, deleteMsg.getBytes());;
        System.out.println("【" + deleteMsg + "】发送成功");

        channel.close();
        connection.close();
    }
}
